﻿using MoetutuServer.Helper;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace MoetutuServer.WebSite.ZeroChan
{
    class ZeroChanDownload
    {
        public static string FileDownload(string Imgurl) {

            String Filename = StaticValue.ImgTemp1 + Path.GetFileName(Imgurl);
            using (WebClient DownloadWebClient = new WebClient())
            {

                DownloadWebClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0");
         
                DownloadWebClient.Headers.Add("Host",new Uri(Imgurl).Host);
                //注意，referer这里写死了文件名获取的方法，这里不应该写死的，如需更改请务必注意

                try
                {
                    DownloadWebClient.DownloadFile(new Uri(Imgurl), Filename);
                }
                catch (Exception ex)
                {
                    PrintLog.Log(ex);
                    Filename = "";
                }



            }
            return Filename;

        }
    }
}
